package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.DamageList;
import com.atguigu.jxc.entity.User;
import com.atguigu.jxc.service.DamageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @author nzmxfan
 * @create 2021-09-04-23:49
 */
@RestController
@RequestMapping("/damageListGoods")
public class DamageController {

    @Autowired
    DamageService damageService;

    /**
     * 保存报损单
     * @param damageList
     * @param damageListGoodsStr
     * @return
     */
    @PostMapping("/save")
    public ServiceVO saveDamage(DamageList damageList, String damageListGoodsStr, HttpSession session){
        // 从 session 域中获取当前用户
        User user = (User)session.getAttribute("currentUser");
        Integer userId = user.getUserId();
        // 用户 id 写入报损单中
        damageList.setUserId(userId);
        // 保存报损单
        damageService.saveDamage(damageList, damageListGoodsStr);
        return new ServiceVO(100,"请求成功", null);

    }

    /**
     * 根据起止时间段查询报损单
     * @param sTime
     * @param eTime
     * @return
     */
    @PostMapping("/list")
    public Map<String,Object> getDamageList(String sTime, String eTime){

        return damageService.getDamageList(sTime, eTime);
    }

    /**
     * 根据起止时间段查询报损单
     * @param damageListId
     * @return
     */
    @PostMapping("/goodsList")
    public Map<String,Object> goodsList(Integer damageListId){

        return damageService.goodsList(damageListId);
    }
}
